from rest_framework import mixins
from rest_framework.generics import GenericAPIView, ListAPIView
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet

from goods.models import GoodsChannel, GoodsChannelGroup, GoodsCategory
from meiduo_admin.serializers.pindao import PindaoSerializer, GoodsChanneltypesSerializer, GoodsCategoriesSerializer


class GoodsChannelView(ModelViewSet):
    permission_classes = [IsAdminUser]
    queryset = GoodsChannel.objects.all()
    serializer_class = PindaoSerializer


class GoodsChanneltypesView(APIView):
    permission_classes = [IsAdminUser]
    pagination_class = None
    # serializer_class = GoodsChanneltypesSerializer
    # queryset = GoodsChannelGroup.objects.all()

    def get(self, request):
        data = GoodsChannelGroup.objects.all()
        serializer = GoodsChanneltypesSerializer(data, many=True)
        return Response(serializer.data)


class GoodsCategoriesView(APIView):
    permission_classes = [IsAdminUser]
    pagination_class = None
    # serializer_class = GoodsCategoriesSerializer
    # queryset = GoodsCategory.objects.filter(parent=None)

    def get(self, request):
        data = GoodsCategory.objects.filter(parent=None)
        serializer = GoodsCategoriesSerializer(data, many=True)
        return Response(serializer.data)
